<?php
namespace S\FileSystem\Handler;

use \S\Config;
use \S\Exception;

abstract class Abstraction implements StoreInterface{

    /**
     * 配置信息
     * @var array
     */
    protected $config = array();
    protected $config_key;
    protected $store_type;

    /**
     * 定义文件存储的configure接口，用来实现配置工作
     * @param string  $type  存储类型(cdn, filesystem)
     * @throws \S\Exception
     */
    public function configure($type) {
        $this->store_type = $type;
        $this->config = Config::confServer($this->store_type.'.'.$this->config_key);

        if (!$this->config) {
            throw new Exception(get_class($this).' need be configured. Config : '.$type."-". $this->config_key);
        }
    }

    /**
     * 检查space名字是否设置
     * @param $space
     * @return bool
     * @throws Exception
     */
    public function checkSpaceName($space){
        $spaces = Config::confServer($this->store_type.".space");
        if(is_array($spaces) && in_array($space, $spaces)){
            return true;
        }else{
            throw new Exception(get_class($this)." space $space is not set");
        }
    }
}